package de.haw.adt.implementation;

import static de.haw.adt.implementation.Values.ZERO;
import de.haw.adt.interfaces.IPhysicsScalar;

abstract class AbstractPhysicalScalar implements IPhysicsScalar {
	
	abstract double getValue();
	
	private int hashDouble() {
		long longBits = Double.doubleToLongBits(getValue());
		return (int) (longBits ^ (longBits >>> 32));
	}
	
	@Override
	public int hashCode() {
		return hashDouble();
	}
	
	public boolean isZero() {
		return getValue() == ZERO;
	}
	
	public boolean isValid() {
		return !Double.isNaN(getValue()) && !Double.isInfinite(getValue());
	}
}
